<%@ page import="org.json.simple.*" %> <%--json_simple_1-1.jar--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    import = "java.sql.*" %>
<%
	request.setCharacterEncoding("UTF-8");
	
	int id_a = Integer.parseInt(request.getParameter("aid"));
	
	String url = "jdbc:oracle:thin:@155.230.193.42:1521:oraknu";
	String user = "system";
	String pass = "DBLab012345";
	Connection con = null;
	String sql = null;
	int result;
	
	JSONObject resultJson = new JSONObject();
	JSONArray resultArray = new JSONArray();

	try
	{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("success");
	}
	catch(ClassNotFoundException e)
	{
		System.err.println("error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con = DriverManager.getConnection(url, user, pass);
	}
	catch(SQLException e)
	{
		System.err.println("sql error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con.setAutoCommit(false);
		
		sql = "select tid, ttext, to_char(tdate, 'yyyy:mm:dd hh:mi:ss') , id_u, id_a from COMMENTTABLE where id_a = ? order by tid desc";
		
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt = con.prepareStatement(sql);
		pstmt.setInt(1, id_a);
	
		ResultSet rs = pstmt.executeQuery();
		
		while(rs.next())
		{
			int id = rs.getInt(1);
			String text = rs.getString(2);
			String date = rs.getString(3);
			String idu = rs.getString(4);
			int ida = rs.getInt(5);

			resultJson = new JSONObject();
			
			resultJson.put("c_id", id);
			resultJson.put("c_text", text);
			resultJson.put("c_date", date);
			resultJson.put("c_id_u", idu);
			resultJson.put("c_id_a", ida);
			resultArray.add(resultJson);
		}
		
		pstmt.close();
		con.close();
	}
	catch(Exception e)
	{
		System.err.println("sql error = " + e.getMessage());
	}
	out.print(resultArray);
%>